forum

home / developersection / forums / write a program to test a switch case using an enum as a string, not an integer in c#.

Write a program to test a switch case using an enum as a string, not an integer in C#.

Ashutosh Patel 476 29-Mar-2023

This is Enum 

 public enum PostType
 {
      Article,
      Blog,
};

I am trying to write code but through  Exception. The code is here.

string  _type = "article";
switch (_type.ToLower())
            {
                case PostType.Article.ToString().ToLower():
                {
                    query = String.Format(@"Up date article");
                    break;
                }
                case PostType.Blog.ToString().ToLower():
                {
                    query = String.Format("UP  date blog");
                    break;
                }
                default: break;
            }

Please help me.


Updated on 30-Mar-2023
Ashutosh Patel

Jr. Software Developer

I am a software developer at MindStick soft. Pvt. ltd. I joined this company in august 2021 after completing my post-graduation course. I love to see the historical places of my country.

Can you answer this question?

Answer

1 Answers

Liked By